{% extends "admin/base.html" %}

{% block admin_content %}
<h3>User Management</h3>

<div class="row">
    <div class="col-md-8">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Username</th>
                        <th>Email</th>
                        <th>Role</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                        <tr>
                            <td>{{ user.id }}</td>
                            <td>{{ user.username }}</td>
                            <td>{{ user.email }}</td>
                            <td>{{ user.role }}</td>
                            <td>
                                {% if user.active %}
                                    <span class="badge bg-success">Active</span>
                                {% else %}
                                    <span class="badge bg-secondary">Inactive</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{{ url_for('admin.edit_user', user_id=user.id) }}" class="btn btn-sm btn-outline-primary">Edit</a>
                                {% if user.active %}
                                    <a href="{{ url_for('admin.deactivate_user', user_id=user.id) }}" class="btn btn-sm btn-outline-warning">Deactivate</a>
                                {% else %}
                                    <a href="{{ url_for('admin.activate_user', user_id=user.id) }}" class="btn btn-sm btn-outline-success">Activate</a>
                                {% endif %}
                                <a href="{{ url_for('admin.delete_user', user_id=user.id) }}" class="btn btn-sm btn-outline-danger" 
                                   onclick="return confirm('Are you sure you want to delete this user?')">Delete</a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5>User Statistics</h5>
            </div>
            <div class="card-body">
                <p><strong>Total Users:</strong> {{ users|length }}</p>
                <p><strong>Active Users:</strong> 10</p>
                <p><strong>Admin Users:</strong> 2</p>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5>Add New User</h5>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ url_for('admin.create_user') }}">
                    <div class="mb-3">
                        <label for="username" class="form-label">Username</label>
                        <input type="text" class="form-control" id="username" name="username" required>
                    </div>
                    <div class="mb-3">
                        <label for="email" class="form-label">Email</label>
                        <input type="email" class="form-control" id="email" name="email" required>
                    </div>
                    <div class="mb-3">
                        <label for="role" class="form-label">Role</label>
                        <select class="form-select" id="role" name="role">
                            <option value="user">User</option>
                            <option value="editor">Editor</option>
                            <option value="admin">Administrator</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-success w-100">Create User</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}